home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / oneko / oneko.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  34KB  |  1,317 lines

  1. /*
  2.  *    oneko  -  X11 $@G-(J
  3.  */
  4.  
  5. #ifndef    lint
  6. static char rcsid[] = "$Header: /home/sun/unix/kato/xsam/oneko/oneko.c,v 1.5 90/10/19 21:25:16 kato Exp $";
  7. #endif
  8.  
  9. #include "oneko.h"
  10. #include "patchlevel.h"
  11. /*
  12.  *    $@%0%m!<%P%kJQ?t(J
  13.  */
  14.  
  15. char    *ClassName = "Oneko";        /* $@%3%^%s%IL>>N(J */
  16. char    *ProgramName;            /* $@%3%^%s%IL>>N(J */
  17.  
  18. Display    *theDisplay;            /* $@%G%#%9%W%l%$9=B$BN(J */
  19. int    theScreen;            /* $@%9%/%j!<%sHV9f(J */
  20. unsigned int    theDepth;        /* $@%G%W%9(J */
  21. Window    theRoot;            /* $@%k!<%H%&%#%s%I%&$N#I#D(J */
  22. Window    theWindow;            /* $@G-%&%#%s%I%&$N#I#D(J */
  23. Cursor    theCursor;            /* $@$M$:$_%+!<%=%k(J */
  24.  
  25. unsigned int    WindowWidth;        /* $@%k!<%H%&%#%s%I%&$NI}(J */
  26. unsigned int    WindowHeight;        /* $@%k!<%H%&%#%s%I%&$N9b$5(J */
  27.  
  28. XColor    theForegroundColor;        /* $@?'(J ($@%U%)%"%0%i%&%s%I(J) */
  29. XColor    theBackgroundColor;        /* $@?'(J ($@%P%C%/%0%i%&%s%I(J) */
  30.  
  31. int Synchronous = False;
  32. /* Types of animals */
  33. #define BITMAPTYPES 3
  34. typedef struct _AnimalDefaults {
  35.   char *name;
  36.   int speed, idle, bitmap_width, bitmap_height;
  37.   long time;
  38.   char *cursor,*mask;
  39.   int cursor_width,cursor_height,cursor_x_hot,cursor_y_hot;
  40. } AnimalDefaultsData;
  41.  
  42. AnimalDefaultsData AnimalDefaultsDataTable[] = 
  43. {
  44.   { "neko", 13, 6, 32, 32, 125000L, mouse_cursor_bits,mouse_cursor_mask_bits,
  45.       mouse_cursor_width,mouse_cursor_height, mouse_cursor_x_hot,mouse_cursor_y_hot },
  46.   { "tora", 16, 6, 32, 32, 125000L, mouse_cursor_bits,mouse_cursor_mask_bits,
  47.       mouse_cursor_width,mouse_cursor_height, mouse_cursor_x_hot,mouse_cursor_y_hot },
  48.   { "dog" , 10, 6, 32, 32, 125000L, bone_cursor_bits,bone_cursor_mask_bits,
  49.       bone_cursor_width,bone_cursor_height, bone_cursor_x_hot,bone_cursor_y_hot },
  50. };
  51.  
  52. /*
  53.  *    $@$$$m$$$m$J=i4|@_Dj(J ($@%*%W%7%g%s!"%j%=!<%9$GJQ$($i$l$k$h(J)
  54.  */
  55.  
  56.                     /* Resource:    */
  57. char    *Foreground = NULL;        /*   foreground    */
  58. char    *Background = NULL;        /*   background    */
  59. long    IntervalTime = 0L;        /*   time    */
  60. double    NekoSpeed = (double)0;        /*   speed    */
  61. int    IdleSpace = 0;            /*   idle    */
  62. int    NekoMoyou = NOTDEFINED;        /*   tora    */
  63. int    NoShape = NOTDEFINED;        /*   noshape    */
  64. int    ReverseVideo = NOTDEFINED;    /*   reverse    */
  65. int     XOffset=0,YOffset=0;            /* X and Y offsets for cat from mouse
  66.                        pointer. */
  67. /*
  68.  *    $@$$$m$$$m$J>uBVJQ?t(J
  69.  */
  70.  
  71. Bool    DontMapped = True;
  72.  
  73. int    NekoTickCount;        /* $@G-F0:n%+%&%s%?(J */
  74. int    NekoStateCount;        /* $@G-F10l>uBV%+%&%s%?(J */
  75. int    NekoState;        /* $@G-$N>uBV(J */
  76.  
  77. int    MouseX;            /* $@%^%&%9#X:BI8(J */
  78. int    MouseY;            /* $@%^%&%9#Y:BI8(J */
  79.  
  80. int    PrevMouseX = 0;        /* $@D>A0$N%^%&%9#X:BI8(J */
  81. int    PrevMouseY = 0;        /* $@D>A0$N%^%&%9#Y:BI8(J */
  82.  
  83. int    NekoX;            /* $@G-#X:BI8(J */
  84. int    NekoY;            /* $@G-#Y:BI8(J */
  85.  
  86. int    NekoMoveDx;        /* $@G-0\F05wN%#X(J */
  87. int    NekoMoveDy;        /* $@G-0\F05wN%#Y(J */
  88.  
  89. int    NekoLastX;        /* $@G-:G=*IA2h#X:BI8(J */
  90. int    NekoLastY;        /* $@G-:G=*IA2h#Y:BI8(J */
  91. GC    NekoLastGC;        /* $@G-:G=*IA2h(J GC */
  92. /* Variables used to set how quickly the program will chose to raise itself. */
  93. /* Look at Interval(), Handle Visiblility Notify Event */
  94. #define DEFAULT_RAISE_WAIT 16  /* About 2 seconds with default interval */
  95. int     RaiseWindowDelay=0;
  96. /*
  97.  *    $@$=$NB>(J
  98.  */
  99.  
  100. double    SinPiPer8Times3;    /* sin($@#3&P!?#8(J) */
  101. double    SinPiPer8;        /* sin($@&P!?#8(J) */
  102.  
  103. Pixmap    Mati2Xbm, Jare2Xbm, Kaki1Xbm, Kaki2Xbm, Mati3Xbm, Sleep1Xbm, Sleep2Xbm;
  104. Pixmap    Mati2Msk, Jare2Msk, Kaki1Msk, Kaki2Msk, Mati3Msk, Sleep1Msk, Sleep2Msk;
  105.  
  106. Pixmap    AwakeXbm, AwakeMsk;
  107.  
  108. Pixmap    Up1Xbm, Up2Xbm, Down1Xbm, Down2Xbm, Left1Xbm, Left2Xbm;
  109. Pixmap    Up1Msk, Up2Msk, Down1Msk, Down2Msk, Left1Msk, Left2Msk;
  110. Pixmap    Right1Xbm, Right2Xbm, UpLeft1Xbm, UpLeft2Xbm, UpRight1Xbm;
  111. Pixmap    Right1Msk, Right2Msk, UpLeft1Msk, UpLeft2Msk, UpRight1Msk;
  112. Pixmap    UpRight2Xbm, DownLeft1Xbm, DownLeft2Xbm, DownRight1Xbm, DownRight2Xbm;
  113. Pixmap    UpRight2Msk, DownLeft1Msk, DownLeft2Msk, DownRight1Msk, DownRight2Msk;
  114.  
  115. Pixmap    UpTogi1Xbm, UpTogi2Xbm, DownTogi1Xbm, DownTogi2Xbm, LeftTogi1Xbm;
  116. Pixmap    UpTogi1Msk, UpTogi2Msk, DownTogi1Msk, DownTogi2Msk, LeftTogi1Msk;
  117. Pixmap    LeftTogi2Xbm, RightTogi1Xbm, RightTogi2Xbm;
  118. Pixmap    LeftTogi2Msk, RightTogi1Msk, RightTogi2Msk;
  119.  
  120. GC      Mati2GC;
  121.  
  122. GC    Jare2GC, Kaki1GC, Kaki2GC, Mati3GC, Sleep1GC, Sleep2GC;
  123.  
  124. GC    AwakeGC;
  125.  
  126. GC    Up1GC, Up2GC, Down1GC, Down2GC, Left1GC, Left2GC, Right1GC, Right2GC;
  127. GC    UpLeft1GC, UpLeft2GC, UpRight1GC, UpRight2GC, DownLeft1GC, DownLeft2GC;
  128. GC    DownRight1GC, DownRight2GC;
  129.  
  130. GC    UpTogi1GC, UpTogi2GC, DownTogi1GC, DownTogi2GC, LeftTogi1GC;
  131. GC    LeftTogi2GC, RightTogi1GC, RightTogi2GC;
  132.  
  133.  
  134. typedef struct {
  135.     GC        *GCCreatePtr;
  136.     Pixmap    *BitmapCreatePtr;
  137.     char    *PixelPattern[BITMAPTYPES];
  138.     Pixmap    *BitmapMasksPtr;
  139.     char    *MaskPattern[BITMAPTYPES];
  140. } BitmapGCData;
  141.  
  142. BitmapGCData    BitmapGCDataTable[] =
  143. {
  144.     { &Mati2GC, &Mati2Xbm, mati2_bits, mati2_tora_bits, mati2_dog_bits,
  145.       &Mati2Msk, mati2_mask_bits, mati2_mask_bits, mati2_dog_mask_bits },
  146.     { &Jare2GC, &Jare2Xbm, jare2_bits, jare2_tora_bits, jare2_dog_bits,
  147.       &Jare2Msk, jare2_mask_bits, jare2_mask_bits, jare2_dog_mask_bits },
  148.     { &Kaki1GC, &Kaki1Xbm, kaki1_bits, kaki1_tora_bits, kaki1_dog_bits,
  149.       &Kaki1Msk, kaki1_mask_bits, kaki1_mask_bits, kaki1_dog_mask_bits },
  150.     { &Kaki2GC, &Kaki2Xbm, kaki2_bits, kaki2_tora_bits, kaki2_dog_bits,
  151.       &Kaki2Msk, kaki2_mask_bits, kaki2_mask_bits, kaki2_dog_mask_bits },
  152.     { &Mati3GC, &Mati3Xbm, mati3_bits, mati3_tora_bits, mati3_dog_bits,
  153.       &Mati3Msk, mati3_mask_bits, mati3_mask_bits, mati3_dog_mask_bits},
  154.     { &Sleep1GC, &Sleep1Xbm, sleep1_bits, sleep1_tora_bits, sleep1_dog_bits,
  155.       &Sleep1Msk, sleep1_mask_bits, sleep1_mask_bits, sleep1_dog_mask_bits },
  156.     { &Sleep2GC, &Sleep2Xbm, sleep2_bits, sleep2_tora_bits, sleep2_dog_bits,
  157.       &Sleep2Msk, sleep2_mask_bits, sleep2_mask_bits, sleep2_dog_mask_bits },
  158.     { &AwakeGC, &AwakeXbm, awake_bits, awake_tora_bits, awake_dog_bits,
  159.       &AwakeMsk, awake_mask_bits, awake_mask_bits, awake_dog_mask_bits },
  160.     { &Up1GC, &Up1Xbm, up1_bits, up1_tora_bits, up1_dog_bits,
  161.       &Up1Msk, up1_mask_bits, up1_mask_bits, up1_dog_mask_bits },
  162.     { &Up2GC, &Up2Xbm, up2_bits, up2_tora_bits, up2_dog_bits,
  163.       &Up2Msk, up2_mask_bits, up2_mask_bits, up2_dog_mask_bits },
  164.     { &Down1GC, &Down1Xbm, down1_bits, down1_tora_bits, down1_dog_bits,
  165.       &Down1Msk, down1_mask_bits, down1_mask_bits, down1_dog_mask_bits },
  166.     { &Down2GC, &Down2Xbm, down2_bits, down2_tora_bits, down2_dog_bits,
  167.       &Down2Msk, down2_mask_bits, down2_mask_bits, down2_dog_mask_bits },
  168.     { &Left1GC, &Left1Xbm, left1_bits, left1_tora_bits, left1_dog_bits,
  169.       &Left1Msk, left1_mask_bits, left1_mask_bits, left1_dog_mask_bits },
  170.     { &Left2GC, &Left2Xbm, left2_bits, left2_tora_bits, left2_dog_bits,
  171.       &Left2Msk, left2_mask_bits, left2_mask_bits, left2_dog_mask_bits },
  172.     { &Right1GC, &Right1Xbm, right1_bits, right1_tora_bits, right1_dog_bits,
  173.       &Right1Msk, right1_mask_bits, right1_mask_bits,right1_dog_mask_bits },
  174.     { &Right2GC, &Right2Xbm, right2_bits, right2_tora_bits, right2_dog_bits,
  175.       &Right2Msk, right2_mask_bits, right2_mask_bits, right2_dog_mask_bits },
  176.     { &UpLeft1GC, &UpLeft1Xbm, upleft1_bits, upleft1_tora_bits, upleft1_dog_bits,
  177.       &UpLeft1Msk, upleft1_mask_bits, upleft1_mask_bits, upleft1_dog_mask_bits },
  178.     { &UpLeft2GC, &UpLeft2Xbm, upleft2_bits, upleft2_tora_bits, upleft2_dog_bits,
  179.       &UpLeft2Msk, upleft2_mask_bits, upleft2_mask_bits,upleft2_dog_mask_bits },
  180.     { &UpRight1GC, &UpRight1Xbm, upright1_bits, upright1_tora_bits, upright1_dog_bits,
  181.       &UpRight1Msk, upright1_mask_bits, upright1_mask_bits,upright1_dog_mask_bits },
  182.     { &UpRight2GC, &UpRight2Xbm, upright2_bits, upright2_tora_bits, upright2_dog_bits,
  183.       &UpRight2Msk, upright2_mask_bits, upright2_mask_bits,upright2_dog_mask_bits },
  184.     { &DownLeft1GC, &DownLeft1Xbm, dwleft1_bits, dwleft1_tora_bits, dwleft1_dog_bits,
  185.       &DownLeft1Msk, dwleft1_mask_bits, dwleft1_mask_bits, dwleft1_dog_mask_bits },
  186.     { &DownLeft2GC, &DownLeft2Xbm, dwleft2_bits, dwleft2_tora_bits, dwleft2_dog_bits,
  187.       &DownLeft2Msk, dwleft2_mask_bits, dwleft2_mask_bits, dwleft2_dog_mask_bits },
  188.     { &DownRight1GC, &DownRight1Xbm, dwright1_bits, dwright1_tora_bits, dwright1_dog_bits,
  189.       &DownRight1Msk, dwright1_mask_bits, dwright1_mask_bits, dwright1_dog_mask_bits },
  190.     { &DownRight2GC, &DownRight2Xbm, dwright2_bits, dwright2_tora_bits, dwright2_dog_bits,
  191.       &DownRight2Msk, dwright2_mask_bits, dwright2_mask_bits, dwright2_dog_mask_bits },
  192.     { &UpTogi1GC, &UpTogi1Xbm, utogi1_bits, utogi1_tora_bits, utogi1_dog_bits,
  193.       &UpTogi1Msk, utogi1_mask_bits, utogi1_mask_bits, utogi1_dog_mask_bits },
  194.     { &UpTogi2GC, &UpTogi2Xbm, utogi2_bits, utogi2_tora_bits, utogi2_dog_bits,
  195.       &UpTogi2Msk, utogi2_mask_bits, utogi2_mask_bits, utogi2_dog_mask_bits },
  196.     { &DownTogi1GC, &DownTogi1Xbm, dtogi1_bits, dtogi1_tora_bits, dtogi1_dog_bits,
  197.       &DownTogi1Msk, dtogi1_mask_bits, dtogi1_mask_bits, dtogi1_dog_mask_bits },
  198.     { &DownTogi2GC, &DownTogi2Xbm, dtogi2_bits, dtogi2_tora_bits, dtogi2_dog_bits,
  199.       &DownTogi2Msk, dtogi2_mask_bits, dtogi2_mask_bits, dtogi2_dog_mask_bits },
  200.     { &LeftTogi1GC, &LeftTogi1Xbm, ltogi1_bits, ltogi1_tora_bits, ltogi1_dog_bits,
  201.       &LeftTogi1Msk, ltogi1_mask_bits, ltogi1_mask_bits,ltogi1_dog_mask_bits },
  202.     { &LeftTogi2GC, &LeftTogi2Xbm, ltogi2_bits, ltogi2_tora_bits, ltogi2_dog_bits,
  203.       &LeftTogi2Msk, ltogi2_mask_bits, ltogi2_mask_bits,ltogi2_dog_mask_bits },
  204.     { &RightTogi1GC, &RightTogi1Xbm, rtogi1_bits, rtogi1_tora_bits, rtogi1_dog_bits,
  205.       &RightTogi1Msk, rtogi1_mask_bits, rtogi1_mask_bits,rtogi1_dog_mask_bits },
  206.     { &RightTogi2GC, &RightTogi2Xbm, rtogi2_bits, rtogi2_tora_bits, rtogi2_dog_bits,
  207.       &RightTogi2Msk, rtogi2_mask_bits, rtogi2_mask_bits,rtogi2_dog_mask_bits },
  208.     { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
  209. };
  210.  
  211. typedef struct {
  212.     GC        *TickGCPtr;
  213.     Pixmap    *TickMaskPtr;
  214. } Animation;
  215.  
  216. Animation    AnimationPattern[][2] =
  217. {
  218.   { { &Mati2GC, &Mati2Msk },
  219.     { &Mati2GC, &Mati2Msk } },        /* NekoState == NEKO_STOP */
  220.   { { &Jare2GC, &Jare2Msk },
  221.     { &Mati2GC, &Mati2Msk } },        /* NekoState == NEKO_JARE */
  222.   { { &Kaki1GC, &Kaki1Msk },
  223.     { &Kaki2GC, &Kaki2Msk } },        /* NekoState == NEKO_KAKI */
  224.   { { &Mati3GC, &Mati3Msk },
  225.     { &Mati3GC, &Mati3Msk } },        /* NekoState == NEKO_AKUBI */
  226.   { { &Sleep1GC, &Sleep1Msk },
  227.     { &Sleep2GC, &Sleep2Msk } },        /* NekoState == NEKO_SLEEP */
  228.   { { &AwakeGC, &AwakeMsk },
  229.     { &AwakeGC, &AwakeMsk } },        /* NekoState == NEKO_AWAKE */
  230.   { { &Up1GC, &Up1Msk },
  231.     { &Up2GC, &Up2Msk } },        /* NekoState == NEKO_U_MOVE */
  232.   { { &Down1GC, &Down1Msk },
  233.     { &Down2GC, &Down2Msk } },        /* NekoState == NEKO_D_MOVE */
  234.   { { &Left1GC, &Left1Msk },
  235.     { &Left2GC, &Left2Msk } },        /* NekoState == NEKO_L_MOVE */
  236.   { { &Right1GC, &Right1Msk },
  237.     { &Right2GC, &Right2Msk } },        /* NekoState == NEKO_R_MOVE */
  238.   { { &UpLeft1GC, &UpLeft1Msk },
  239.     { &UpLeft2GC, &UpLeft2Msk } },    /* NekoState == NEKO_UL_MOVE */
  240.   { { &UpRight1GC, &UpRight1Msk },
  241.     { &UpRight2GC, &UpRight2Msk } },    /* NekoState == NEKO_UR_MOVE */
  242.   { { &DownLeft1GC, &DownLeft1Msk },
  243.     { &DownLeft2GC, &DownLeft2Msk } },    /* NekoState == NEKO_DL_MOVE */
  244.   { { &DownRight1GC, &DownRight1Msk },
  245.     { &DownRight2GC, &DownRight2Msk } },    /* NekoState == NEKO_DR_MOVE */
  246.   { { &UpTogi1GC, &UpTogi1Msk },
  247.     { &UpTogi2GC, &UpTogi2Msk } },    /* NekoState == NEKO_U_TOGI */
  248.   { { &DownTogi1GC, &DownTogi1Msk },
  249.     { &DownTogi2GC, &DownTogi2Msk } },    /* NekoState == NEKO_D_TOGI */
  250.   { { &LeftTogi1GC, &LeftTogi1Msk },
  251.     { &LeftTogi2GC, &LeftTogi2Msk } },    /* NekoState == NEKO_L_TOGI */
  252.   { { &RightTogi1GC, &RightTogi1Msk },
  253.     { &RightTogi2GC, &RightTogi2Msk } },    /* NekoState == NEKO_R_TOGI */
  254. };
  255.  
  256. static void NullFunction();
  257.  
  258. /*
  259.  *    $@%S%C%H%^%C%W%G!<%?!&(JGC $@=i4|2=(J
  260.  */
  261.  
  262. void
  263. InitBitmapAndGCs()
  264. {
  265.     BitmapGCData    *BitmapGCDataTablePtr;
  266.     XGCValues        theGCValues;
  267.  
  268.     theGCValues.function = GXcopy;
  269.     theGCValues.foreground = theForegroundColor.pixel;
  270.     theGCValues.background = theBackgroundColor.pixel;
  271.     theGCValues.fill_style = FillTiled;
  272.     theGCValues.ts_x_origin = 0;
  273.     theGCValues.ts_y_origin = 0;
  274.  
  275.     for (BitmapGCDataTablePtr = BitmapGCDataTable;
  276.      BitmapGCDataTablePtr->GCCreatePtr != NULL;
  277.      BitmapGCDataTablePtr++) {
  278.  
  279.     *(BitmapGCDataTablePtr->BitmapCreatePtr)
  280.         = XCreatePixmapFromBitmapData(theDisplay, theRoot,
  281.         BitmapGCDataTablePtr->PixelPattern[NekoMoyou],
  282.         BITMAP_WIDTH, BITMAP_HEIGHT,
  283.         theForegroundColor.pixel,
  284.         theBackgroundColor.pixel,
  285.         DefaultDepth(theDisplay, theScreen));
  286.  
  287.     theGCValues.tile = *(BitmapGCDataTablePtr->BitmapCreatePtr);
  288.  
  289.     *(BitmapGCDataTablePtr->BitmapMasksPtr)
  290.         = XCreateBitmapFromData(theDisplay, theRoot,
  291.         BitmapGCDataTablePtr->MaskPattern[NekoMoyou],
  292.         BITMAP_WIDTH, BITMAP_HEIGHT);
  293.  
  294.     *(BitmapGCDataTablePtr->GCCreatePtr)
  295.         = XCreateGC(theDisplay, theWindow,
  296.         GCFunction | GCForeground | GCBackground | GCTile |
  297.         GCTileStipXOrigin | GCTileStipYOrigin | GCFillStyle,
  298.         &theGCValues);
  299.     }
  300. }
  301.  
  302. /*
  303.  *    $@%j%=!<%9!&%G!<%?%Y!<%9$+$iI,MW$J%j%=!<%9$r<h$j=P$9(J
  304.  */
  305.  
  306. char    *
  307. NekoGetDefault(resource)
  308. char    *resource;
  309. {
  310.     char    *value;
  311.  
  312.     if (value = XGetDefault(theDisplay, ProgramName, resource)) {
  313.         return value;
  314.     }
  315.     if (value = XGetDefault(theDisplay, ClassName, resource)) {
  316.         return value;
  317.     }
  318.     return NULL;
  319. }
  320.  
  321. /*
  322.  *    $@%j%=!<%9!&%G!<%?%Y!<%9$+$i%*%W%7%g%s$r@_Dj(J
  323.  */
  324.  
  325. GetResources()
  326. {
  327.   char    *resource;
  328.   int        num;
  329.   int loop;
  330.   if (Foreground == NULL) {
  331.     if ((resource = NekoGetDefault("foreground")) != NULL) {
  332.       Foreground = resource;
  333.     }
  334.   }
  335.  
  336.   if (Background == NULL) {
  337.     if ((resource = NekoGetDefault("background")) != NULL) {
  338.       Background = resource;
  339.     }
  340.   }
  341.  
  342.   if (IntervalTime == 0) {
  343.     if ((resource = NekoGetDefault("time")) != NULL) {
  344.       if (num = atoi(resource)) {
  345.     IntervalTime = num;
  346.       }
  347.     }
  348.   }
  349.  
  350.   if (NekoSpeed == (double)0) {
  351.     if ((resource = NekoGetDefault("speed")) != NULL) {
  352.       if (num = atoi(resource)) {
  353.     NekoSpeed = (double)num;
  354.       }
  355.     }
  356.   }
  357.  
  358.   if (IdleSpace == 0) {
  359.     if ((resource = NekoGetDefault("idle")) != NULL) {
  360.       if (num = atoi(resource)) {
  361.     IdleSpace = num;
  362.       }
  363.     }
  364.   }
  365.  
  366.   if (NekoMoyou == NOTDEFINED) {
  367.     for (loop=0;loop<BITMAPTYPES;loop++)
  368.       if ((resource = NekoGetDefault(AnimalDefaultsDataTable[loop].name)) != NULL) {
  369.     if (IsTrue(resource))
  370.       NekoMoyou = loop;
  371.       }
  372.   }
  373.  
  374.   if (NoShape == NOTDEFINED) {
  375.     if ((resource = NekoGetDefault("noshape")) != NULL) {
  376.       NoShape = IsTrue(resource);
  377.     }
  378.   }
  379.  
  380.   if (ReverseVideo == NOTDEFINED) {
  381.     if ((resource = NekoGetDefault("reverse")) != NULL) {
  382.       ReverseVideo = IsTrue(resource);
  383.     }
  384.   }
  385.  
  386.   if (Foreground == NULL) {
  387.     Foreground = DEFAULT_FOREGROUND;
  388.   }
  389.   if (Background == NULL) {
  390.     Background = DEFAULT_BACKGROUND;
  391.   }
  392.   if (NekoMoyou == NOTDEFINED) {
  393.     NekoMoyou = 0;
  394.   }
  395.   if (IntervalTime == 0) {
  396.     IntervalTime = AnimalDefaultsDataTable[NekoMoyou].time;
  397.   }
  398.   if (NekoSpeed == (double)0) {
  399.     NekoSpeed = (double)(AnimalDefaultsDataTable[NekoMoyou].speed);
  400.   }
  401.   if (IdleSpace == 0) {
  402.     IdleSpace = AnimalDefaultsDataTable[NekoMoyou].idle;
  403.   }
  404.   if (NoShape == NOTDEFINED) {
  405.     NoShape = False;
  406.   }
  407.   if (ReverseVideo == NOTDEFINED) {
  408.     ReverseVideo = False;
  409.   }
  410. }
  411.  
  412. /*
  413.  *    $@$M$:$_7?%+!<%=%k$r:n$k(J
  414.  */
  415.  
  416. MakeMouseCursor()
  417. {
  418.     Pixmap            theCursorSource;
  419.     Pixmap            theCursorMask;
  420.  
  421.     theCursorSource
  422.     = XCreateBitmapFromData(theDisplay, theRoot,
  423.                 AnimalDefaultsDataTable[NekoMoyou].cursor, 
  424.                 AnimalDefaultsDataTable[NekoMoyou].cursor_width,
  425.                 AnimalDefaultsDataTable[NekoMoyou].cursor_height);
  426.  
  427.     theCursorMask
  428.     = XCreateBitmapFromData(theDisplay, theRoot,
  429.                 AnimalDefaultsDataTable[NekoMoyou].mask,
  430.                 AnimalDefaultsDataTable[NekoMoyou].cursor_width,
  431.                 AnimalDefaultsDataTable[NekoMoyou].cursor_height);
  432.  
  433.     theCursor = XCreatePixmapCursor(theDisplay, theCursorSource, theCursorMask,
  434.                     &theBackgroundColor, &theForegroundColor,
  435.                     AnimalDefaultsDataTable[NekoMoyou].cursor_x_hot,
  436.                     AnimalDefaultsDataTable[NekoMoyou].cursor_y_hot);
  437.     XFreePixmap(theDisplay,theCursorSource);
  438.     XFreePixmap(theDisplay,theCursorMask);
  439. }
  440.  
  441. /*
  442.  *    $@?'$r=i4|@_Dj$9$k(J
  443.  */
  444.  
  445. SetupColors()
  446. {
  447.     XColor    theExactColor;
  448.     Colormap    theColormap;
  449.  
  450.     theColormap = DefaultColormap(theDisplay, theScreen);
  451.  
  452.     if (theDepth == 1) {
  453.     Foreground = "black";
  454.     Background = "white";
  455.     }
  456.  
  457.     if (ReverseVideo == True) {
  458.     char    *tmp;
  459.  
  460.     tmp = Foreground;
  461.     Foreground = Background;
  462.     Background = tmp;
  463.     }
  464.  
  465.     if (!XAllocNamedColor(theDisplay, theColormap,
  466.         Foreground, &theForegroundColor, &theExactColor)) {
  467.     fprintf(stderr, "%s: Can't XAllocNamedColor(\"%s\").\n",
  468.         ProgramName, Foreground);
  469.     exit(1);
  470.     }
  471.  
  472.     if (!XAllocNamedColor(theDisplay, theColormap,
  473.         Background, &theBackgroundColor, &theExactColor)) {
  474.     fprintf(stderr, "%s: Can't XAllocNamedColor(\"%s\").\n",
  475.         ProgramName, Background);
  476.     exit(1);
  477.     }
  478. }
  479.  
  480. /*
  481.  *    $@%9%/%j!<%s4D6-=i4|2=(J
  482.  */
  483.  
  484. void
  485. InitScreen(DisplayName)
  486.     char    *DisplayName;
  487. {
  488.   XSetWindowAttributes    theWindowAttributes;
  489.   unsigned long        theWindowMask;
  490.   Window            theTempRoot;
  491.   int                WindowPointX;
  492.   int                WindowPointY;
  493.   unsigned long        BorderWidth;
  494.   int                event_base, error_base;
  495.  
  496.   if ((theDisplay = XOpenDisplay(DisplayName)) == NULL) {
  497.     fprintf(stderr, "%s: Can't open display", ProgramName);
  498.     if (DisplayName != NULL) {
  499.       fprintf(stderr, " %s.\n", DisplayName);
  500.     } else {
  501.       fprintf(stderr, ".\n");
  502.     }
  503.     exit(1);
  504.   }
  505.  
  506.   GetResources();
  507.  
  508.   if (Synchronous == True) {
  509.     fprintf(stderr,"Synchronizing.\n");
  510.     XSynchronize(theDisplay,True);
  511.   }
  512.  
  513. #ifdef SHAPE
  514.   if (!NoShape && XShapeQueryExtension(theDisplay,
  515.                        &event_base, &error_base) == False) {
  516.     fprintf(stderr, "Display not suported shape extension.\n");
  517.     NoShape = True;
  518.                        }
  519. #endif SHAPE
  520.  
  521.   theScreen = DefaultScreen(theDisplay);
  522.   theDepth = DefaultDepth(theDisplay, theScreen);
  523.  
  524.   theRoot = RootWindow(theDisplay, theScreen);
  525.  
  526.   XGetGeometry(theDisplay, theRoot, &theTempRoot,
  527.            &WindowPointX, &WindowPointY,
  528.            &WindowWidth, &WindowHeight,
  529.            &BorderWidth, &theDepth);
  530.  
  531.   SetupColors();
  532.   MakeMouseCursor();
  533.  
  534.   theWindowAttributes.background_pixel = theBackgroundColor.pixel;
  535.   theWindowAttributes.cursor = theCursor;
  536.   theWindowAttributes.override_redirect = True;
  537.  
  538.   theWindowMask = CWCursor;
  539.   XChangeWindowAttributes(theDisplay, theRoot, theWindowMask,
  540.               &theWindowAttributes);
  541.  
  542.   theWindowMask = CWBackPixel        |
  543.     CWCursor        |
  544.       CWOverrideRedirect;
  545.  
  546.   theWindow = XCreateWindow(theDisplay, theRoot, 0, 0,
  547. #ifdef SHAPE
  548.                 (NoShape == False)? WindowWidth: BITMAP_WIDTH,
  549.                 (NoShape == False)? WindowHeight: BITMAP_HEIGHT,
  550. #else SHAPE
  551.                 BITMAP_WIDTH, BITMAP_HEIGHT,
  552. #endif SHAPE
  553.                 0, theDepth, InputOutput, CopyFromParent,
  554.                 theWindowMask, &theWindowAttributes);
  555.  
  556.   XStoreName(theDisplay, theWindow, ProgramName);
  557.  
  558.   InitBitmapAndGCs();
  559.  
  560.   XSelectInput(theDisplay, theWindow, 
  561.            ExposureMask|VisibilityChangeMask|KeyPressMask);
  562.  
  563.   XFlush(theDisplay);
  564. }
  565.  
  566.  
  567. /*
  568.  *    $@%$%s%?!<%P%k(J
  569.  *
  570.  *    $@!!$3$N4X?t$r8F$V$H!"$"$k0lDj$N;~4VJV$C$F$3$J$/$J$k!#G-(J
  571.  *    $@$NF0:n%?%$%_%s%0D4@0$KMxMQ$9$k$3$H!#(J
  572.  */
  573.  
  574. void
  575. Interval()
  576. {
  577.     pause();
  578.     if (RaiseWindowDelay>0)
  579.       RaiseWindowDelay--;
  580. }
  581.  
  582.  
  583. /*
  584.  *    $@%F%#%C%/%+%&%s%H=hM}(J
  585.  */
  586.  
  587. void
  588. TickCount()
  589. {
  590.     if (++NekoTickCount >= MAX_TICK) {
  591.     NekoTickCount = 0;
  592.     }
  593.  
  594.     if (NekoTickCount % 2 == 0) {
  595.     if (NekoStateCount < MAX_TICK) {
  596.         NekoStateCount++;
  597.     }
  598.     }
  599. }
  600.  
  601.  
  602. /*
  603.  *    $@G->uBV@_Dj(J
  604.  */
  605.  
  606. void
  607. SetNekoState(SetValue)
  608.     int        SetValue;
  609. {
  610.     NekoTickCount = 0;
  611.     NekoStateCount = 0;
  612.  
  613.     NekoState = SetValue;
  614. }
  615.  
  616.  
  617. /*
  618.  *    $@G-IA2h=hM}(J
  619.  */
  620.  
  621. void
  622. DrawNeko(x, y, DrawAnime)
  623.     int        x;
  624.     int        y;
  625.     Animation    DrawAnime;
  626. {
  627. /*@@@@@@*/
  628.     register GC        DrawGC = *(DrawAnime.TickGCPtr);
  629.     register Pixmap    DrawMask = *(DrawAnime.TickMaskPtr);
  630.  
  631.     if ((x != NekoLastX) || (y != NekoLastY)
  632.         || (DrawGC != NekoLastGC)) {
  633.  
  634. #ifdef SHAPE
  635.     if (NoShape == False) {
  636.         XShapeCombineMask(theDisplay, theWindow, ShapeBounding,
  637.         x, y, DrawMask, ShapeSet);
  638.  
  639.         if (DontMapped) {
  640.         XMapRaised(theDisplay, theWindow);
  641.         DontMapped = 0;
  642.         }
  643.  
  644.         XSetTSOrigin(theDisplay, DrawGC, x, y);
  645.  
  646.         XFillRectangle(theDisplay, theWindow, DrawGC,
  647.         x, y, BITMAP_WIDTH, BITMAP_HEIGHT);
  648.     } else
  649. #endif SHAPE
  650.     {
  651.         XWindowChanges    theChanges;
  652.  
  653.         theChanges.x = x;
  654.         theChanges.y = y;
  655.         XConfigureWindow(theDisplay, theWindow, CWX | CWY, &theChanges);
  656.  
  657.         if (DontMapped) {
  658.         XMapWindow(theDisplay, theWindow);
  659.         DontMapped = 0;
  660.         }
  661.  
  662.         XFillRectangle(theDisplay, theWindow, DrawGC,
  663.         0, 0, BITMAP_WIDTH, BITMAP_HEIGHT);
  664.     }
  665.     }
  666.  
  667.     XFlush(theDisplay);
  668.  
  669.     NekoLastX = x;
  670.     NekoLastY = y;
  671.  
  672.     NekoLastGC = DrawGC;
  673. }
  674.  
  675.  
  676. /*
  677.  *    $@G-:FIA2h=hM}(J
  678.  */
  679.  
  680. void
  681. RedrawNeko()
  682. {
  683. #ifdef SHAPE
  684.     if (NoShape == False) {
  685.     XFillRectangle(theDisplay, theWindow, NekoLastGC,
  686.         NekoLastX, NekoLastY,
  687.         BITMAP_WIDTH, BITMAP_HEIGHT);
  688.     } else
  689. #endif SHAPE
  690.     {
  691.     XFillRectangle(theDisplay, theWindow, NekoLastGC,
  692.         0, 0, BITMAP_WIDTH, BITMAP_HEIGHT);
  693.     }
  694.  
  695.     XFlush(theDisplay);
  696. }
  697.  
  698.  
  699. /*
  700.  *    $@G-0\F0J}K!7hDj(J
  701.  *
  702.  *      This sets the direction that the neko is moving.
  703.  *
  704.  */
  705.  
  706. void
  707. NekoDirection()
  708. {
  709.     int            NewState;
  710.     double        LargeX, LargeY;
  711.     double        Length;
  712.     double        SinTheta;
  713.  
  714.     if (NekoMoveDx == 0 && NekoMoveDy == 0) {
  715.     NewState = NEKO_STOP;
  716.     } else {
  717.     LargeX = (double)NekoMoveDx;
  718.     LargeY = (double)(-NekoMoveDy);
  719.     Length = sqrt(LargeX * LargeX + LargeY * LargeY);
  720.     SinTheta = LargeY / Length;
  721.  
  722.     if (NekoMoveDx > 0) {
  723.         if (SinTheta > SinPiPer8Times3) {
  724.         NewState = NEKO_U_MOVE;
  725.         } else if ((SinTheta <= SinPiPer8Times3)
  726.             && (SinTheta > SinPiPer8)) {
  727.         NewState = NEKO_UR_MOVE;
  728.         } else if ((SinTheta <= SinPiPer8)
  729.             && (SinTheta > -(SinPiPer8))) {
  730.         NewState = NEKO_R_MOVE;
  731.         } else if ((SinTheta <= -(SinPiPer8))
  732.             && (SinTheta > -(SinPiPer8Times3))) {
  733.         NewState = NEKO_DR_MOVE;
  734.         } else {
  735.         NewState = NEKO_D_MOVE;
  736.         }
  737.     } else {
  738.         if (SinTheta > SinPiPer8Times3) {
  739.         NewState = NEKO_U_MOVE;
  740.         } else if ((SinTheta <= SinPiPer8Times3)
  741.             && (SinTheta > SinPiPer8)) {
  742.         NewState = NEKO_UL_MOVE;
  743.         } else if ((SinTheta <= SinPiPer8)
  744.             && (SinTheta > -(SinPiPer8))) {
  745.         NewState = NEKO_L_MOVE;
  746.         } else if ((SinTheta <= -(SinPiPer8))
  747.             && (SinTheta > -(SinPiPer8Times3))) {
  748.         NewState = NEKO_DL_MOVE;
  749.         } else {
  750.         NewState = NEKO_D_MOVE;
  751.         }
  752.     }
  753.     }
  754.  
  755.     if (NekoState != NewState) {
  756.     SetNekoState(NewState);
  757.     }
  758. }
  759.  
  760.  
  761. /*
  762.  *    $@G-JI$V$D$+$jH=Dj(J
  763.  */
  764.  
  765. Bool
  766. IsWindowOver()
  767. {
  768.     Bool    ReturnValue = False;
  769.  
  770.     if (NekoY <= 0) {
  771.     NekoY = 0;
  772.     ReturnValue = True;
  773.     } else if (NekoY >= WindowHeight - BITMAP_HEIGHT) {
  774.     NekoY = WindowHeight - BITMAP_HEIGHT;
  775.     ReturnValue = True;
  776.     }
  777.     if (NekoX <= 0) {
  778.     NekoX = 0;
  779.     ReturnValue = True;
  780.     } else if (NekoX >= WindowWidth - BITMAP_WIDTH) {
  781.     NekoX = WindowWidth - BITMAP_WIDTH;
  782.     ReturnValue = True;
  783.     }
  784.  
  785.     return(ReturnValue);
  786. }
  787.  
  788.  
  789. /*
  790.  *    $@G-0\F0>u67H=Dj(J
  791.  */
  792.  
  793. Bool
  794. IsNekoDontMove()
  795. {
  796.     if (NekoX == NekoLastX && NekoY == NekoLastY) {
  797.     return(True);
  798.     } else {
  799.     return(False);
  800.     }
  801. }
  802.  
  803.  
  804. /*
  805.  *    $@G-0\F03+;OH=Dj(J
  806.  */
  807.  
  808. Bool
  809. IsNekoMoveStart()
  810. {
  811.     if ((PrevMouseX >= MouseX - IdleSpace
  812.      && PrevMouseX <= MouseX + IdleSpace) &&
  813.      (PrevMouseY >= MouseY - IdleSpace 
  814.      && PrevMouseY <= MouseY + IdleSpace)) {
  815.     return(False);
  816.     } else {
  817.     return(True);
  818.     }
  819. }
  820.  
  821.  
  822. /*
  823.  *    $@G-0\F0(J dx, dy $@7W;;(J
  824.  */
  825.  
  826. void
  827. CalcDxDy()
  828. {
  829.     Window        QueryRoot, QueryChild;
  830.     int            AbsoluteX, AbsoluteY;
  831.     int            RelativeX, RelativeY;
  832.     unsigned int    ModKeyMask;
  833.     double        LargeX, LargeY;
  834.     double        DoubleLength, Length;
  835.  
  836.     XQueryPointer(theDisplay, theWindow,
  837.            &QueryRoot, &QueryChild,
  838.            &AbsoluteX, &AbsoluteY,
  839.            &RelativeX, &RelativeY,
  840.            &ModKeyMask);
  841.  
  842.     PrevMouseX = MouseX;
  843.     PrevMouseY = MouseY;
  844.  
  845.     MouseX = AbsoluteX+XOffset;
  846.     MouseY = AbsoluteY+YOffset;
  847.  
  848.     LargeX = (double)(MouseX - NekoX - BITMAP_WIDTH / 2);
  849.     LargeY = (double)(MouseY - NekoY - BITMAP_HEIGHT);
  850.  
  851.     DoubleLength = LargeX * LargeX + LargeY * LargeY;
  852.  
  853.     if (DoubleLength != (double)0) {
  854.     Length = sqrt(DoubleLength);
  855.     if (Length <= NekoSpeed) {
  856.         NekoMoveDx = (int)LargeX;
  857.         NekoMoveDy = (int)LargeY;
  858.     } else {
  859.         NekoMoveDx = (int)((NekoSpeed * LargeX) / Length);
  860.         NekoMoveDy = (int)((NekoSpeed * LargeY) / Length);
  861.     }
  862.     } else {
  863.     NekoMoveDx = NekoMoveDy = 0;
  864.     }
  865. }
  866.  
  867.  
  868. /*
  869.  *    $@F0:n2r@OG-IA2h=hM}(J
  870.  */
  871.  
  872. void
  873. NekoThinkDraw()
  874. {
  875.     CalcDxDy();
  876.  
  877.     if (NekoState != NEKO_SLEEP) {
  878.     DrawNeko(NekoX, NekoY,
  879.         AnimationPattern[NekoState][NekoTickCount & 0x1]);
  880.     } else {
  881.     DrawNeko(NekoX, NekoY,
  882.         AnimationPattern[NekoState][(NekoTickCount >> 2) & 0x1]);
  883.     }
  884.  
  885.     TickCount();
  886.  
  887.     switch (NekoState) {
  888.     case NEKO_STOP:
  889.     if (IsNekoMoveStart()) {
  890.         SetNekoState(NEKO_AWAKE);
  891.         break;
  892.     }
  893.     if (NekoStateCount < NEKO_STOP_TIME) {
  894.         break;
  895.     }
  896.     if (NekoMoveDx < 0 && NekoX <= 0) {
  897.         SetNekoState(NEKO_L_TOGI);
  898.     } else if (NekoMoveDx > 0 && NekoX >= WindowWidth - BITMAP_WIDTH) {
  899.         SetNekoState(NEKO_R_TOGI);
  900.     } else if (NekoMoveDy < 0 && NekoY <= 0) {
  901.         SetNekoState(NEKO_U_TOGI);
  902.     } else if (NekoMoveDy > 0 && NekoY >= WindowHeight - BITMAP_HEIGHT) {
  903.         SetNekoState(NEKO_D_TOGI);
  904.     } else {
  905.         SetNekoState(NEKO_JARE);
  906.     }
  907.     break;
  908.     case NEKO_JARE:
  909.     if (IsNekoMoveStart()) {
  910.         SetNekoState(NEKO_AWAKE);
  911.         break;
  912.     }
  913.     if (NekoStateCount < NEKO_JARE_TIME) {
  914.         break;
  915.     }
  916.     SetNekoState(NEKO_KAKI);
  917.     break;
  918.     case NEKO_KAKI:
  919.     if (IsNekoMoveStart()) {
  920.         SetNekoState(NEKO_AWAKE);
  921.         break;
  922.     }
  923.     if (NekoStateCount < NEKO_KAKI_TIME) {
  924.         break;
  925.     }
  926.     SetNekoState(NEKO_AKUBI);
  927.     break;
  928.     case NEKO_AKUBI:
  929.     if (IsNekoMoveStart()) {
  930.         SetNekoState(NEKO_AWAKE);
  931.         break;
  932.     }
  933.     if (NekoStateCount < NEKO_AKUBI_TIME) {
  934.         break;
  935.     }
  936.     SetNekoState(NEKO_SLEEP);
  937.     break;
  938.     case NEKO_SLEEP:
  939.     if (IsNekoMoveStart()) {
  940.         SetNekoState(NEKO_AWAKE);
  941.         break;
  942.     }
  943.     break;
  944.     case NEKO_AWAKE:
  945.     if (NekoStateCount < NEKO_AWAKE_TIME) {
  946.         break;
  947.     }
  948.     NekoDirection();    /* $@G-$,F0$/8~$-$r5a$a$k(J */
  949.     break;
  950.     case NEKO_U_MOVE:
  951.     case NEKO_D_MOVE:
  952.     case NEKO_L_MOVE:
  953.     case NEKO_R_MOVE:
  954.     case NEKO_UL_MOVE:
  955.     case NEKO_UR_MOVE:
  956.     case NEKO_DL_MOVE:
  957.     case NEKO_DR_MOVE:
  958.     NekoX += NekoMoveDx;
  959.     NekoY += NekoMoveDy;
  960.     NekoDirection();
  961.     if (IsWindowOver()) {
  962.         if (IsNekoDontMove()) {
  963.         SetNekoState(NEKO_STOP);
  964.         }
  965.     }
  966.     break;
  967.     case NEKO_U_TOGI:
  968.     case NEKO_D_TOGI:
  969.     case NEKO_L_TOGI:
  970.     case NEKO_R_TOGI:
  971.     if (IsNekoMoveStart()) {
  972.         SetNekoState(NEKO_AWAKE);
  973.         break;
  974.     }
  975.     if (NekoStateCount < NEKO_TOGI_TIME) {
  976.         break;
  977.     }
  978.     SetNekoState(NEKO_KAKI);
  979.     break;
  980.     default:
  981.     /* Internal Error */
  982.     SetNekoState(NEKO_STOP);
  983.     break;
  984.     }
  985.  
  986.     Interval();
  987. }
  988.  
  989.  
  990. /*
  991.  *    $@%-!<%$%Y%s%H=hM}(J
  992.  */
  993.  
  994. Bool
  995. ProcessKeyPress(theKeyEvent)
  996.     XKeyEvent    *theKeyEvent;
  997. {
  998.   int            Length;
  999.   int            theKeyBufferMaxLen = AVAIL_KEYBUF;
  1000.   char        theKeyBuffer[AVAIL_KEYBUF + 1];
  1001.   KeySym        theKeySym;
  1002.   XComposeStatus    theComposeStatus;
  1003.   Bool        ReturnState;
  1004.  
  1005.   ReturnState = True;
  1006.  
  1007.   Length = XLookupString(theKeyEvent,
  1008.              theKeyBuffer, theKeyBufferMaxLen,
  1009.              &theKeySym, &theComposeStatus);
  1010.  
  1011.   if (Length > 0) {
  1012.     switch (theKeyBuffer[0]) {
  1013.     case 'q':
  1014.     case 'Q':
  1015.       if (theKeyEvent->state & Mod1Mask) { /* META (Alt) $@%-!<(J */
  1016.     ReturnState = False;
  1017.       }
  1018.       break;
  1019.     default:
  1020.       break;
  1021.     }
  1022.     puts("Key Event");
  1023.   }
  1024.  
  1025.   return(ReturnState);
  1026. }
  1027.  
  1028.  
  1029. /*
  1030.  *    $@%$%Y%s%H=hM}(J
  1031.  */
  1032.  
  1033. Bool
  1034. ProcessEvent()
  1035. {
  1036.     XEvent    theEvent;
  1037.     Bool    ContinueState = True;
  1038.  
  1039.     while (XPending(theDisplay)) {
  1040.         XNextEvent(theDisplay,&theEvent);
  1041.     switch (theEvent.type) {
  1042.     case Expose:
  1043.         if (theEvent.xexpose.count == 0) {
  1044.         RedrawNeko();
  1045.         }
  1046.         break;
  1047.     case KeyPress:
  1048.         ContinueState = ProcessKeyPress(&theEvent);
  1049.         if (!ContinueState) {
  1050.             return(ContinueState);
  1051.         }
  1052.         break;
  1053.     case VisibilityNotify:
  1054.         if (RaiseWindowDelay==0) {
  1055.           XRaiseWindow(theDisplay,theWindow);
  1056.           RaiseWindowDelay=DEFAULT_RAISE_WAIT;
  1057.         } 
  1058.     default:
  1059.         /* Unknown Event */
  1060.         break;
  1061.     }
  1062.     }
  1063.  
  1064.     return(ContinueState);
  1065. }
  1066.  
  1067.  
  1068. /*
  1069.  *    $@G-=hM}(J
  1070.  */
  1071.  
  1072. void
  1073. ProcessNeko()
  1074. {
  1075.   struct itimerval    Value;
  1076.  
  1077.   /* $@G-$N=i4|2=(J */
  1078.  
  1079.   NekoX = (WindowWidth - BITMAP_WIDTH / 2) / 2;
  1080.   NekoY = (WindowHeight - BITMAP_HEIGHT / 2) / 2;
  1081.  
  1082.   NekoLastX = NekoX;
  1083.   NekoLastY = NekoY;
  1084.  
  1085.   SetNekoState(NEKO_STOP);
  1086.  
  1087.   /* $@%?%$%^!<@_Dj(J */
  1088.  
  1089.   timerclear(&Value.it_interval);
  1090.   timerclear(&Value.it_value);
  1091.  
  1092.   Value.it_interval.tv_usec = IntervalTime;
  1093.   Value.it_value.tv_usec = IntervalTime;
  1094.  
  1095.   setitimer(ITIMER_REAL, &Value, 0);
  1096.  
  1097.   /* $@%a%$%s=hM}(J */
  1098.  
  1099.   do {
  1100.     NekoThinkDraw();
  1101.   } while (ProcessEvent());
  1102. }
  1103.  
  1104.  
  1105. /*
  1106.  *    SIGALRM $@%7%0%J%k=hM}(J
  1107.  */
  1108.  
  1109. static void
  1110. NullFunction()
  1111. {
  1112.   /* No Operation */
  1113. #ifdef SYSV
  1114.   signal(SIGALRM, NullFunction);
  1115. #endif /* SYSV */
  1116. }
  1117.  
  1118. /*
  1119.  *    SIGINT $@%7%0%J%k=hM}(J
  1120.  */
  1121.  
  1122. void
  1123. RestoreCursor()
  1124. {
  1125.   XSetWindowAttributes    theWindowAttributes;
  1126.   BitmapGCData *BitmapGCDataTablePtr;
  1127.  
  1128.   theWindowAttributes.cursor = None;
  1129.   XChangeWindowAttributes(theDisplay, theRoot, CWCursor,
  1130.               &theWindowAttributes);
  1131.   for (BitmapGCDataTablePtr = BitmapGCDataTable;
  1132.        BitmapGCDataTablePtr->GCCreatePtr != NULL;
  1133.        BitmapGCDataTablePtr++) {
  1134.     XFreePixmap(theDisplay,*(BitmapGCDataTablePtr->BitmapCreatePtr));
  1135.     XFreePixmap(theDisplay,*(BitmapGCDataTablePtr->BitmapMasksPtr));
  1136.     XFreeGC(theDisplay,*(BitmapGCDataTablePtr->GCCreatePtr));
  1137.        }
  1138.   XFreeCursor(theDisplay,theCursor);
  1139.   XCloseDisplay(theDisplay);
  1140.   exit(0);
  1141. }
  1142.  
  1143.  
  1144. /*
  1145.  *    Usage
  1146.  */
  1147.  
  1148. char    *message[] = {
  1149. "",
  1150. "Options are:",
  1151. "-display <display>    : Neko appears on specified display.",
  1152. "-fg <color>        : Foreground color",
  1153. "-bg <color>        : Background color",
  1154. "-speed <dots>",
  1155. "-time <microseconds>",
  1156. "-idle <dots>",
  1157. "-rv            : Reverse video. (effects monochrome display only)",
  1158. "-position <geometry>   : as position of geometry, relative to mouse pointer.",
  1159. "-debug                 : puts you in synchronous mode.",
  1160. "-patchlevel            : print out your current patchlevel.",
  1161. NULL };
  1162.  
  1163. void
  1164. Usage()
  1165. {
  1166.   char    **mptr;
  1167.   int loop;
  1168.  
  1169.   mptr = message;
  1170.   fprintf(stderr, "Usage: %s [<options>]\n", ProgramName);
  1171.   while (*mptr) {
  1172.     fprintf(stderr,"%s\n", *mptr);
  1173.     mptr++;
  1174.   }
  1175.   for (loop=0;loop<BITMAPTYPES;loop++)
  1176.     fprintf(stderr,"-%s Use %s bitmaps\n",AnimalDefaultsDataTable[loop].name,AnimalDefaultsDataTable[loop].name);
  1177. }
  1178.  
  1179.  
  1180. /*
  1181.  *    $@%*%W%7%g%s$NM}2r(J
  1182.  */
  1183.  
  1184. Bool
  1185. GetArguments(argc, argv, theDisplayName)
  1186.     int        argc;
  1187.     char    *argv[];
  1188.     char    *theDisplayName;
  1189. {
  1190.   int        ArgCounter;
  1191.   int    result,foo,bar;
  1192.   extern int XOffset,YOffset;
  1193.   int loop,found=0;
  1194.  
  1195.   theDisplayName[0] = '\0';
  1196.  
  1197.   for (ArgCounter = 0; ArgCounter < argc; ArgCounter++) {
  1198.  
  1199.     if (strncmp(argv[ArgCounter], "-h", 2) == 0) {
  1200.       Usage();
  1201.       exit(0);
  1202.     }
  1203.     if (strcmp(argv[ArgCounter], "-display") == 0) {
  1204.       ArgCounter++;
  1205.       if (ArgCounter < argc) {
  1206.     strcpy(theDisplayName, argv[ArgCounter]);
  1207.       } else {
  1208.     fprintf(stderr, "%s: -display option error.\n", ProgramName);
  1209.     exit(1);
  1210.       }
  1211.     }
  1212.     else if (strcmp(argv[ArgCounter], "-speed") == 0) {
  1213.       ArgCounter++;
  1214.       if (ArgCounter < argc) {
  1215.     NekoSpeed = atof(argv[ArgCounter]);
  1216.       } else {
  1217.     fprintf(stderr, "%s: -speed option error.\n", ProgramName);
  1218.     exit(1);
  1219.       }
  1220.     }
  1221.     else if (strcmp(argv[ArgCounter], "-time") == 0) {
  1222.       ArgCounter++;
  1223.       if (ArgCounter < argc) {
  1224.     IntervalTime = atol(argv[ArgCounter]);
  1225.       } else {
  1226.     fprintf(stderr, "%s: -time option error.\n", ProgramName);
  1227.     exit(1);
  1228.       }
  1229.     }
  1230.     else if (strcmp(argv[ArgCounter], "-idle") == 0) {
  1231.       ArgCounter++;
  1232.       if (ArgCounter < argc) {
  1233.     IdleSpace = atol(argv[ArgCounter]);
  1234.       } else {
  1235.     fprintf(stderr, "%s: -idle option error.\n", ProgramName);
  1236.     exit(1);
  1237.       }
  1238.     }
  1239.     else if ((strcmp(argv[ArgCounter], "-fg") == 0) ||
  1240.          (strcmp(argv[ArgCounter], "-foreground") == 0)) {
  1241.       ArgCounter++;
  1242.       Foreground = argv[ArgCounter];
  1243.          }
  1244.     else if ((strcmp(argv[ArgCounter], "-bg") == 0) ||
  1245.          (strcmp(argv[ArgCounter], "-background") == 0)) {
  1246.       ArgCounter++;
  1247.       Background = argv[ArgCounter];
  1248.          }
  1249.     else if (strcmp(argv[ArgCounter], "-rv") == 0) {
  1250.       ReverseVideo = True;
  1251.     }
  1252.     else if (strcmp(argv[ArgCounter], "-noshape") == 0) {
  1253.       NoShape = True;
  1254.     }
  1255.     else if (strcmp(argv[ArgCounter], "-position") == 0) {
  1256.       ArgCounter++;
  1257.       result=XParseGeometry(argv[ArgCounter],&XOffset,&YOffset,&foo,&bar);
  1258.     }
  1259.     else if (strcmp(argv[ArgCounter], "-debug") ==0) {
  1260.       Synchronous = True;
  1261.     }
  1262.     else if (strcmp(argv[ArgCounter], "-patchlevel") == 0) {
  1263.       fprintf(stderr,"Patchlevel :%s\n",PATCHLEVEL);
  1264.     }
  1265.     else {
  1266.       for (loop=0;loop<BITMAPTYPES;loop++)
  1267.     if (strcmp(argv[ArgCounter]+1,AnimalDefaultsDataTable[loop].name)==0)
  1268.       {NekoMoyou = loop;found=1;}
  1269.       if (!found) {
  1270.     fprintf(stderr,
  1271.         "%s: Unknown option \"%s\".\n", ProgramName,
  1272.         argv[ArgCounter]);
  1273.     Usage();
  1274.     exit(1);
  1275.       }
  1276.     }
  1277.   }
  1278.  
  1279.   if (strlen(theDisplayName) < 1) {
  1280.     theDisplayName = NULL;
  1281.   }
  1282. }
  1283.  
  1284.  
  1285. /*
  1286.  *    $@%a%$%s4X?t(J
  1287.  */
  1288.  
  1289. int
  1290. main(argc, argv)
  1291.     int        argc;
  1292.     char    *argv[];
  1293. {
  1294.   char    theDisplayName[MAXDISPLAYNAME];
  1295.  
  1296.   ProgramName = argv[0];
  1297.  
  1298.   argc--;
  1299.   argv++;
  1300.  
  1301.   GetArguments(argc, argv, theDisplayName);
  1302.  
  1303.   InitScreen(theDisplayName);
  1304.  
  1305.   signal(SIGALRM, NullFunction);
  1306.   signal(SIGINT, RestoreCursor);
  1307.   signal(SIGTERM, RestoreCursor);
  1308.   signal(SIGQUIT, RestoreCursor);
  1309.  
  1310.   SinPiPer8Times3 = sin(PI_PER8 * (double)3);
  1311.   SinPiPer8 = sin(PI_PER8);
  1312.  
  1313.   ProcessNeko();
  1314.  
  1315.   RestoreCursor();
  1316. }
  1317.